﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
using YArchitech.LIB;

namespace YArchitech.Plumbing.ParamForm
{
	public partial class DiameterTableForm : System.Windows.Forms.Form
	{
		public DiameterTableForm()
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
		}

		private void DiameterTableForm_Load(object sender, EventArgs e)
		{
			this.dgvDiameter.Rows.Clear();
			this.dgvDiameter.Rows.Add(new object[]
			{
				"",
				"De16",
				"12"
			});
			this.dgvDiameter.Rows.Add(new object[]
			{
				"",
				"De20",
				"16"
			});
			this.dgvDiameter.Rows.Add(new object[]
			{
				"",
				"De25",
				"20"
			});
		}

		private void btnDefault_Click(object sender, EventArgs e)
		{
			this.dgvDiameter.Rows.Clear();
			this.dgvDiameter.Rows.Add(new object[]
			{
				"",
				"De16",
				"12"
			});
			this.dgvDiameter.Rows.Add(new object[]
			{
				"",
				"De20",
				"16"
			});
			this.dgvDiameter.Rows.Add(new object[]
			{
				"",
				"De25",
				"20"
			});
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void btnHelp_Click(object sender, EventArgs e)
		{
			new DiameterTableHelpForm().ShowDialog();
		}

		private void dgvDiameter_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
		{
		}

		private void toolNew_Click(object sender, EventArgs e)
		{
			this.dgvDiameter.Rows.Add(new object[0]);
		}

		private void toolAdd_Click(object sender, EventArgs e)
		{
			this.dgvDiameter.Rows.Insert(this.iRowIndex, Array.Empty<object>());
		}

		private void toolDel_Click(object sender, EventArgs e)
		{
			this.dgvDiameter.Rows.RemoveAt(this.iRowIndex);
		}

		private void toolUp_Click(object sender, EventArgs e)
		{
			if (this.iRowIndex >= 1)
			{
				this.MoveRow(this.iRowIndex - 1);
			}
		}

		private void toolDown_Click(object sender, EventArgs e)
		{
			if (this.iRowIndex < this.dgvDiameter.Rows.Count - 1)
			{
				this.MoveRow(this.iRowIndex + 1);
			}
		}

		private void toolHome_Click(object sender, EventArgs e)
		{
			if (this.iRowIndex >= 1)
			{
				this.MoveRow(0);
			}
		}

		private void toolEnd_Click(object sender, EventArgs e)
		{
			if (this.iRowIndex < this.dgvDiameter.Rows.Count - 1)
			{
				this.MoveRow(this.dgvDiameter.Rows.Count - 1);
			}
		}

		private void MoveRow(int rowIndex)
		{
			DataGridViewRow dataGridViewRow = this.dgvDiameter.Rows[this.iRowIndex];
			this.dgvDiameter.Rows.Remove(this.dgvDiameter.Rows[this.iRowIndex]);
			this.dgvDiameter.Rows.Insert(rowIndex, dataGridViewRow);
			this.dgvDiameter.Rows[rowIndex].Selected = true;
			this.dgvDiameter.CurrentCell.Selected = false;
		}

		private void dgvDiameter_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
		{
			int num = e.RowIndex + 1;
			SolidBrush brush = new SolidBrush(this.dgvDiameter.RowHeadersDefaultCellStyle.ForeColor);
			e.Graphics.DrawString(num.ToString(CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, brush, (float)(e.RowBounds.Location.X + 5), (float)(e.RowBounds.Location.Y + 4));
		}

		private int iRowIndex;
	}
}
